package BackOffice;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.swing.JButton;

import javax.swing.JPasswordField;
import javax.swing.JSeparator;
import javax.swing.WindowConstants;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JTextField;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class Login extends javax.swing.JPanel {
	{
		// Set Look & Feel
		try {
			javax.swing.UIManager
					.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	private JTextField Name;
	private JPasswordField Passwort;
	private JButton Login;
	private JSeparator jSeparator2;
	private JSeparator jSeparator1;
	private JLabel JBnamen;
	private JTextField idUSER;
	private JLabel JFehler;
	private JButton Exit;
	private JLabel JMax;
	private JLabel LPasswort;
	private JLabel LVorname;
	private JTextField Vorname;
	private JLabel LName;
	private Connection conn = null;

	/**
	 * Auto-generated main method to display this JPanel inside a new JFrame.
	 */
	public static void main(String[] args) {
		JFrame frame = new JFrame();
		frame.getContentPane().add(new Login());
		frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		frame.pack();
		frame.setVisible(true);
	}

	public Login() {
		super();
		initGUI();
	}

	private void initGUI() {
		try {
			this.setPreferredSize(new java.awt.Dimension(800, 600));
			this.setLayout(null);
			{
				Name = new JTextField();
				this.add(Name);
				Name.setBounds(339, 147, 112, 23);
			}
			{
				LName = new JLabel();
				this.add(LName);
				LName.setText("Name");
				LName.setBounds(206, 150, 109, 16);
			}
			{
				Vorname = new JTextField();
				this.add(Vorname);
				Vorname.setBounds(339, 192, 112, 23);
			}
			{
				LVorname = new JLabel();
				this.add(LVorname);
				LVorname.setText("Vorname");
				LVorname.setBounds(206, 195, 121, 16);
			}
			{
				Passwort = new JPasswordField();
				this.add(Passwort);
				Passwort.setBounds(339, 232, 112, 23);
			}
			{
				LPasswort = new JLabel();
				this.add(LPasswort);
				LPasswort.setText("Passwort");
				LPasswort.setBounds(206, 235, 115, 16);
			}
			{
				JMax = new JLabel();
				this.add(JMax);
				JMax.setText("(Maximal 16 Zeichen)");
				JMax.setBounds(463, 235, 167, 16);
			}
			{
				Login = new JButton();
				this.add(Login);
				Login.setText("Login");
				Login.setBounds(327, 290, 136, 84);
				Login.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						LoginActionPerformed(evt);
					}
				});
			}
			{
				Exit = new JButton();
				this.add(Exit);
				Exit.setText("Exit");
				Exit.setBounds(361, 411, 75, 45);
				Exit.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						ExitActionPerformed(evt);
					}
				});
			}
			{
				JFehler = new JLabel();
				this.add(JFehler);
				JFehler.setBounds(255, 56, 325, 21);
			}
			{
				idUSER = new JTextField();
				this.add(idUSER);
				idUSER.setBounds(339, 104, 112, 23);
			}
			{
				JBnamen = new JLabel();
				this.add(JBnamen);
				JBnamen.setText("Benutzernamen");
				JBnamen.setBounds(206, 110, 121, 12);
			}
			{
				jSeparator1 = new JSeparator();
				this.add(jSeparator1);
				jSeparator1.setBounds(164, 278, 480, 10);
			}
			{
				jSeparator2 = new JSeparator();
				this.add(jSeparator2);
				jSeparator2.setBounds(164, 389, 480, 10);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private void ExitActionPerformed(ActionEvent evt) {
		System.exit(0);
	}

	private void LoginActionPerformed(ActionEvent evt) {
		if (!Statements.login(Name.getText(), Vorname.getText(), Passwort.getText(), idUSER.getText())) {
			JFehler.setText("\u00DCberpruefen Sie Ihre Eingabe");
		} else {
			JFehler.setText("");
			Start.getStart().getContentPane().removeAll();
			Hauptmenue H = new Hauptmenue();
			Start.getStart().add(H);
			Start.getStart().validate();
		}

	}

}
